function hasCycle(head) {
    if (!head || !head.next) return false;
    let fast = head.next;
    let slow = head;
    while (fast != slow) {
        if (!fast && !fast.next) return false;
        fast = fast.next.next;
        slow = slow.next;
    }
    return true;
}

/**
 * 使用hash
 * @param {*} head 
 * @returns 
 */
function hasCycle(head) {
    if (!head || !head.next) return false;
    let o = new WeakMap();
    // let fast = head.next;
    let slow = head;
    while (slow) {
        if (o.get(slow)) {
            return true;
        }
        o.set(slow, 1);
        // if (!fast && !fast.next) return false;
        // fast = fast.next.next;
        slow = slow.next;
    }
    return true;
}
